package com.mapper;

import com.domain.BlogComment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {

    @Delete("DELETE FROM t_comment WHERE article_id = #{id}")
    int deleteCommentWithId(Integer id);

    @Select("SELECT * FROM t_comment WHERE article_id = #{id} ORDER BY id DESC")
    List<BlogComment> selectCommentWithPage(Integer id);

    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    List<BlogComment> selectNewComment();

    @Insert("INSERT INTO t_comment (article_id, created, author, ip, content)" +
            "VALUES (#{articleId}, #{created}, #{author}, #{ip}, #{content})")
    int pushComment(BlogComment comment);

    @Select("SELECT COUNT(1) FROM t_comment")
    int countComment();

}
